package com.module.launcher.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;

import com.module.base.utils.DisplayUtils;
import com.module.launcher.R;

/**
 * 首次登录点击同意dialog
 */
public class AgreeDialog extends Dialog {

    private Context mContext;
    private String url;


    public AgreeDialog(Context context, View.OnClickListener onClickListener) {
        this(context, R.style.BaseDialog, onClickListener);
    }

    View.OnClickListener onClickListener;

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public AgreeDialog(@NonNull Context context, @StyleRes int themeResId, View.OnClickListener onClickListener) {
        super(context, themeResId);
        this.mContext = context;
        this.onClickListener = onClickListener;
        initView(url);
    }

    private void initView(String url) {
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.launcher_dialog_agree, null, false);

        inflate.findViewById(R.id.tv_law).setOnClickListener(onClickListener);
        inflate.findViewById(R.id.tv_private).setOnClickListener(onClickListener);
        inflate.findViewById(R.id.btn_no_agree).setOnClickListener(onClickListener);
        inflate.findViewById(R.id.btn_agree).setOnClickListener(onClickListener);

//        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);


        setContentView(inflate);


    }

    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams2 = window.getAttributes();
        layoutParams2.gravity = Gravity.CENTER;
        layoutParams2.width = DisplayUtils.dip2px(300);
        window.setAttributes(layoutParams2);
    }
}
